


using PolicyAlgebra.Util;

namespace PolicyAlgebra.Type
{
	///<summary>
	///    This class defines a set that associates a role with
	///    a set of permissions sets.
	///</summary>
	public class ObjectPermissionSetSetAssociationSet : Set<ObjectPermissionSetSetAssociation>
	{ 

		///<summary>
		/// Constructor.
		///</summary>
		///<param name="perms">The permissions (possibly none) that should be in the set upon construction</param>
		public ObjectPermissionSetSetAssociationSet(params ObjectPermissionSetSetAssociation[] perms) : base(perms) { }

		//
		// Below follows the methods that are used to compare two of these sets.


		///<summary>
		/// This operator checks two sets for equality.
		///</summary>
		///<param name="s1">The first set in the comparison</param>
		///<param name="s2">The second set in the comparison</param>
		public static bool operator ==(ObjectPermissionSetSetAssociationSet s1, ObjectPermissionSetSetAssociationSet s2)
		{
			return s1.Equals(s2);
		}


		///<summary>
		/// This operator checks two sets for inequality.
		///</summary>
		///<param name="s1">The first set in the comparison</param>
		///<param name="s2">The second set in the comparison</param>
		public static bool operator !=(ObjectPermissionSetSetAssociationSet s1, ObjectPermissionSetSetAssociationSet s2)
		{
			return !(s1.Equals(s2));
		}


		///<summary>
		/// This method checks two sets for equality (the instance that the
		/// method is called upon and the supplied one).
		///</summary>
		///<param name="s1">The supplied set for comparison</param>
		public override bool Equals(object s1)
		{
			if (! (s1 is ObjectPermissionSetSetAssociationSet))
			{
				return false;
			}

			foreach (ObjectPermissionSetSetAssociation m in (ObjectPermissionSetSetAssociationSet) s1)
			{
				if (! this.IsMember(m))
				{
					return false;
				}
			}

			return true;
		}


		///<summary>
		/// Compute a hashcode for an object of this type.
		///</summary>
		///<returns>Integer hashcode</returns>
		public override int GetHashCode()
		{
			return base.GetHashCode();
		}
	}
}
